import axios from 'axios';
import $ from 'jquery'

const isSameUser =  null;
const isSameLab =  null;

export default{

  isSameUser, 
  isSameLab,

	objToArr:function (acceptObj){
      let newarr = [];
      for(var prop in acceptObj){
        newarr.push(acceptObj[prop]);
      }
      return newarr
    },

    arrToObj:function(acceptarr){
    	let newobj={};
    	for( var i = 0 ; i < acceptarr.length ; i++ ){
    		newobj[acceptarr[i].id] = acceptarr[i];
    	}
    	return newobj;
    },

    test:function(){
      console.log('test')
    },


    axiosTest:function(){
        axios.get('/static/test.json')
        .then(function (response) {
          console.log(response);
        })
        .catch(function (response) {
          console.log(response);
        });
    },

    commitData:function (url, data, callbackfun, method, dataType) {
      if (method == null) {
        // 默认post方式
        method = "post";
      }
      if (dataType == null) {
        // 默认json数据类型
        dataType = "json";
      }
      if (callbackfun.error == null) {
        // 默认输出错误日志
        callbackfun.error = function(error) {
          // top.dialog({
          //   title : "操作异常",
          //   content : "操作异常",
          //   quickClose : true
          // }).show();
          console.log(error)
        };
      }
      $.ajax({
        url : url,
        dataType : dataType,
        type : method,
        data : data,
        headers : {
          "returntype" : "ajax/json"
        },
        traditional : true,
        success : function(data) {
          console.log(url)
          if (data.code >= 10000 && data.code < 11000) {
            if (data.code == 10000) {
              top.location.href = "/login.htm";
              return;
            }
          }
          if (callbackfun.success)
            callbackfun.success(data);
        },
        error : function(error){
          if(callbackfun.error)
            callbackfun.error(error)
        }
      });
    }

}